package com.example.mq.rabbit.spring;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class StompProducer {

    public static void main(String[] args) throws IOException, TimeoutException {
        //创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("xrb");
        factory.setPassword("xrb");
        factory.setVirtualHost("/");
        factory.setHost("192.168.116.130");
        //建立到代理服务器的连接
        Connection conn = factory.newConnection();
        //创建信道
        Channel channel = conn.createChannel();
        String exchangeName = "exchange-stomp";
        //声明Topic类型的交换器
        channel.exchangeDeclare(exchangeName, "topic");
        String routingKey = "shopping.discount";
        String message = "<a href='https://www.baidu.com' target='black'>微醺好时光，美酒3件七折，抢购猛戳</a>";
        //发布消息
        channel.basicPublish(exchangeName, routingKey, null, message.getBytes());
        channel.close();
        conn.close();

    }
}
